<?php
class SourceAction extends Action {
    public function index(){
        init($this);
        $this->MenuSelected="Source";
        $this->detail = "This is a download leading page please go to the course page or the problem page to click the download button.";
        // not finished;
        // $model = new Model();
        // $res = $model->table('data')
        //              ->join('subject on subject.SubId=data.SubId')
        $this->display();
    }
    public function del() {
        init($this);
        $did = $this->_get("did");
        if (isset($did)){
            // to be added: uploader can del the source;
            if ($this->UserLevel== 3) {
                // need to add a valid property
                $sql = M('Data');
                $sql->delete($did);
            }
        }
        echo "<script>window.location.href='javascript:history.go(-2)';</script>";
    }
    public function upload() {
        init($this);
        if ($this->UserLevel == 0) {
            // need to be continue;
        }
        else {
            // 文件上传
            import('ORG.Net.UploadFile');
            $upload = new UploadFile();// 实例化上传类
            $upload->maxSize  = 3145728;// 设置附件上传大小
            $upload->allowExts  = array();// 设置附件上传类型
            $upload->savePath =  '/Upload/';// 设置附件上传目录
            if(!$upload->upload()) {// 上传错误提示错误信息
                $this->error($upload->getErrorMsg());
            }
            else {
                $info = $upload->getUploadFileInfo();
                $cid = $this->_post("cid");
                $uid = $this->UserId;
                $ans = D('Data');
                $data["SubId"] = $cid;
                $data["UserId"] = $uid;
                $data["DataLink"] = $info["savepath"].$info["name"];
                $ans->create($data);
                $ans->add();
            }
        }
        gohistory();
    }
}
?>
